﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Odyssey.Linq;

namespace Odyssey.Web.Models
{
    public class SessionManager
    {

        public static bool IsLogin()
        {
            return User != null;
        }

        public static void Clear()
        {
            HttpContext.Current.Session.Clear();
        }

        public static List<tb_user_permit> UserPermits
        {
            get { return Get<List<tb_user_permit>>("UsersPermits"); }
            set { Set("UsersPermits", value); }
        }

        public static tb_user User
        {
            get { return Get<tb_user>("Users"); }
            set { Set("Users", value); }
        }

        private static void Set<T>(string key, T value)
        {
            HttpContext.Current.Session[key] = value; 
        }

        private static T Get<T>(string key)
        {
            object value = HttpContext.Current.Session[key];
            return DataConverter.To<T>(value);
        }
    }
}